//
//  QSAppConstant.swift
//  TestSwift
//
//  Created by Song on 2018/4/26.
//  Copyright © 2018 Song. All rights reserved.
//

import UIKit

/// App相关信息
let kInfoDic = Bundle.main.infoDictionary
// 获取App的版本号
let kAppVersion = kInfoDic?["CFBundleShortVersionString"]
// 获取App的build版本
let kAppBuildVersion = kInfoDic?["CFBundleVersion"]
// 获取App的名称
let kAppName = kInfoDic?["CFBundleDisplayName"]

/// 屏幕Bounds
let kScreenBounds = UIScreen.main.bounds
// 屏幕宽度
let kScreenWidth: CGFloat = UIScreen.main.bounds.size.width
// 屏幕高度
let kScreenHeight: CGFloat = UIScreen.main.bounds.size.height

/// 全面屏手机的安全区域
func kSafaAreaInset() -> UIEdgeInsets {
    if #available(iOS 11.0, *) {
        return UIApplication.shared.delegate?.window??.safeAreaInsets ?? UIEdgeInsets.zero
    } else {
        return UIEdgeInsets.zero
    }
}

/// 是否是刘海屏
func kIsBangScreen() -> Bool {
    return kSafaAreaInset().top > 20
}

/// 状态栏的高度
let kStatusBarHeight = UIApplication.shared.statusBarFrame.height
/// 导航栏高度
let kNavBarHeight = UINavigationController().navigationBar.frame.height + kStatusBarHeight
/// tabBar高度
let kTabBarHeight = UITabBarController().tabBar.frame.height + kSafaAreaInset().bottom

/// 获取window
let kWindow = UIApplication.shared.keyWindow

/// 宽度适配
func kAdaptedWidth(_ value: CGFloat) -> CGFloat {
    if kIsBangScreen() {
        // 刘海屏
        let kWidthScale = kScreenWidth / 414.0
        return CGFloat(value * kWidthScale)
    } else {
        // iPhone5s ~ iPhone8
        let kWidthScale = kScreenWidth / 375.0
        return CGFloat(value * kWidthScale)
    }
}

/// 高度适配
func kAdaptedHeight(_ value: CGFloat) -> CGFloat {
    if kIsBangScreen() {
        // 刘海屏
        let kHeightScale = kScreenHeight / 896.0
        return CGFloat(value * kHeightScale)
    } else {
        // iPhone5s ~ iPhone8
        let kHeightScale = kScreenHeight / 667.0
        return CGFloat(value * kHeightScale)
    }
}

/// 日志打印
func QSLog(_ items: Any...) {
    #if DEBUG
    print(items)
    #else
    #endif
}
